#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 105;

int n, m;
char c[N][N];
int g[N][N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) rep(j, 1, n) cin >> c[i][j];
  rep(i, 1, n) rep(j, 1, n) g[i][j] = -1;
  queue<pii> q;
  rep(i, 1, n) g[i][i] = 0, q.push(pii(i, i));
  rep(i, 1, n) rep(j, 1, n) {
    if (i == j || c[i][j] == '-') continue;
    g[i][j] = 1, q.push(pii(i, j));
  }
  while (q.size()) {
    pii now = q.front();
    q.pop();
    int u = now.first, v = now.second;
    rep(i, 1, n) rep(j, 1, n) {
      if (g[i][j] == -1 && c[i][u] == c[v][j] && c[i][u] != '-')
        g[i][j] = g[u][v] + 2, q.push(pii(i, j));
    }
  }
  rep(i, 1, n) {
    rep(j, 1, n) cout << g[i][j] << ' ';
    cout << endl;
  }
  return 0;
}